using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace DocumentManagement
{
  /// <summary>
  /// TLifeinsur Data Object Class
  /// </summary>
  public partial class DOTLifeinsur
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the TLifeinsur lifeinsur
		/// </summary>
		public const string Rowlifeinsur = "lifeinsur";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTLifeinsur_Create";
private const string m_StoredProcedureConstDelete = "spTLifeinsur_Delete";
private const string m_StoredProcedureConstRetrieve = "spTLifeinsur_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTLifeinsur_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTLifeinsur_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_lifeinsur;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTLifeinsur> m_TLifeinsurs = new List<DOTLifeinsur>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTLifeinsur() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// lifeinsur
		/// </summary>
		/// <remarks>
		/// This property contains the TLifeinsur lifeinsur
		/// </remarks>
		public string lifeinsur
		{
			get { return (this.m_lifeinsur); }
			set { this.m_lifeinsur = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTLifeinsur> TLifeinsurs
	{
	  get { return m_TLifeinsurs; }
	  set { m_TLifeinsurs = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + Rowlifeinsur + "=" + this.lifeinsur);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[Rowlifeinsur].ToString() != "")
			this.lifeinsur = dr[Rowlifeinsur].ToString();
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTLifeinsur TLifeinsur = new DOTLifeinsur();
			
					if (dr[Rowlifeinsur].ToString() != "")
			TLifeinsur.lifeinsur = dr[Rowlifeinsur].ToString();

            this.TLifeinsurs.Add(TLifeinsur);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
